package com.viknix.threadpool.manager.client.service;

import java.util.concurrent.*;

/**
 * @Author: Dongqi
 * @Date: 2021/11/24 10:07
 * @Version 1.0
 * @Description:
 */
public class TimerService {

    static public ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialDelay,
                                                            long delay, TimeUnit unit) {
        return scheduledExecutor.scheduleWithFixedDelay(command, initialDelay, delay, unit);
    }

    @SuppressWarnings("PMD.ThreadPoolCreationRule")
    static ScheduledExecutorService scheduledExecutor = Executors
            .newSingleThreadScheduledExecutor(new ThreadFactory() {
                @Override
                public Thread newThread(Runnable r) {
                    Thread t = new Thread(r);
                    t.setName("com.viknix.tpm.client.Timer");
                    t.setDaemon(true);
                    return t;
                }
            });
}
